<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/taglib/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/taglib/struts-logic.tld" prefix="logic" %>

<!-- ******************** Localization ******************** -->
<bean:define id="previous_password"><bean:message key="base.profile.previous_password"/></bean:define>
<bean:define id="new_password"><bean:message key="base.profile.new_password"/></bean:define>
<bean:define id="repeat_password"><bean:message key="base.profile.repeat_password"/></bean:define>


<!-- ############################ Validation ############################  -->

<script type="text/javascript">
	function isValid() {
		var isValid = true;
		
		var oldPassword = document.getElementById("oldPasswordCheck").firstChild.value;
		var newPassword = document.getElementById("newPassword").firstChild.value;
		var newPasswordConfirm = document.getElementById("newPasswordConfirm").firstChild.value;
		
		if( oldPassword == "" ) {
			alert("Введите старый пароль!");
			isValid = false;
		}
		else if( newPassword.length < 8 ) {
			alert("Пароль должен состоять не менее, чем из 8 символов!");
			isValid = false;
		}
		else if( newPassword != newPasswordConfirm ) {
			alert("Проверьте повторный ввод!");
			isValid = false;
		}
		return isValid;
	}
</script>


<div id="content" align="center" >
	<div style="color:red"><html:errors /></div>
	<html:form action="/profile" method="post" onsubmit="return isValid();" > 
		<table>
			<tr>
				<td><%=previous_password%>: </td>
				<td id="oldPasswordCheck"><html:password property="oldPasswordCheck" /></td>
			</tr>
			<tr>
				<td><%=new_password%>: </td>
				<td id="newPassword"><html:password property="newPassword" /></td>
			</tr>
			<tr>
				<td><%=repeat_password%>:</td>
				<td id="newPasswordConfirm"><html:password property="newPasswordConfirm" /></td>
			</tr>
			<tr>
				<html:hidden property="formIsLoaded" value="false" />
				<td colspan="2" align="center"><html:submit property="method" value="save" /></td>
			</tr>
		</table>
	</html:form>
</div>